package com.ftt;
import com.google.gson.Gson;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

public class Util {



        public static void writerData(HttpServletResponse resp, List list){
            //将list对象转换为JSON格式字符串
            Gson gson = new Gson();
            String result = gson.toJson(list);
            //获取输出流
            //设置响应的内容类型
            resp.setContentType("application/json");
            //设置响应的数据编码格式
            resp.setCharacterEncoding("utf-8");
            //输出响应的数据
            try {
                resp.getWriter().print(result);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
       /** 生成订单的编号 */
        public static String createOrderId(){
            LocalDateTime now = LocalDateTime.now();
            return "" + now.getYear() + (now.getMonthValue()<10?"0"+now.getMonthValue():now.getMonthValue())
                    + (now.getDayOfMonth()<10?"0"+now.getDayOfMonth():now.getDayOfMonth()) + now.toLocalTime().toString().replace(".","").replace(":","");
        }
}
